package com.shawn.baseappbygroovydsl.ui.sharedpreferences

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.shawn.baseappbygroovydsl.databinding.FragmentSpBinding
import com.shawn.baseappbygroovydsl.spf.SPFTask

class SPFragment : Fragment() {

    private lateinit var _binding: FragmentSpBinding

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val slideshowViewModel =
            ViewModelProvider(this).get(SPViewModel::class.java)
        _binding = FragmentSpBinding.inflate(inflater, container, false)
        val root: View = binding.root
        initView()
        initClick()
        return root
    }

    private fun initView() {
        binding.tvSp.text = "本地存储数字:%s".format(SPFTask.intTemp)
    }

    private fun initClick() {
        binding.btnAdd.setOnClickListener {
            SPFTask.intTemp += 1
            binding.tvSp.text = "本地存储数字:%s".format(SPFTask.intTemp)
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()

    }
}